﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;
using System.Security.Claims;

namespace Manon.Admin.ApplicationCore.Common
{

    public class IdentityUser : IIdentityUser 
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        public IdentityUser(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
       
        public int UserId
        {
            get
            {
                var auth = _httpContextAccessor.HttpContext.AuthenticateAsync();
                var _userId = auth.Result.Principal.Claims.First(t => t.Type.Equals("UserId")).Value;
                int _intUserId = 0;
                int.TryParse(_userId, out _intUserId);
                return _intUserId;
            }
            set { }
        }
        public string UserName
        {
            get
            {
                var auth = _httpContextAccessor.HttpContext.AuthenticateAsync();
                var userName = auth.Result.Principal.Claims.First(t => t.Type.Equals(ClaimTypes.Name)).Value;
                return userName;
            }

            set { }
        }
        public string RealName
        {
            get
            {
                var auth = _httpContextAccessor.HttpContext.AuthenticateAsync();
                var RealName = auth.Result.Principal.Claims.First(t => t.Type.Equals("RealName")).Value;
                return RealName;

            }

            set { }
        }
    }

}
